1 import java.io.*;
2 import java.net.*;
3 import java.util.*;
4
5 public class HTTPOut extends Thread {
6
7 ReqQueue myQueue;
8 Logging myLog;
9 Fetch f;
10 Request currentRequest;
11 FetchResult result;
12 public boolean idle = true;
13
14 // Use default constructor
15
16 public void init(ReqQueue yourQueue, Logging yourLog) {
17 setDaemon(true);
18 myQueue = yourQueue;
19 myLog = yourLog;
20 f = new Fetch();
21 }
22
23 public void run() {
24
25 // Loop until killed by the world
26 while(true) {
27 if (myQueue.size() > 0)
28 {
29 idle = false;
30 currentRequest = myQueue.get();
31
32 switch(currentRequest.type) {
33
34 case Request.reqPUT:
35 try {
36 URL url = new URL(currentRequest.text);
37 result = f.get(url);
38
39 if (result == null) {
40 System.out.println("NULL result!");
41 } else {
42 myLog.post("P : " + result.status +
43 " t=" + result.time + " s=" + result.size + "\n : " + currentRequest.text);
44 }
45
46 } catch (MalformedURLException em) {
47
48 myLog.post("DISCARD: Script item discarded do to malformed URL");
49 myLog.post(" : " + currentRequest.text);
50 }
51 break;
52
53 case Request.reqWAIT:
54 try {
55 this.sleep(currentRequest.intParam);
56 // myLog.post("WAIT: CHUTE Cleared after "+currentRequest.intParam);
57 } catch (Exception e) {
58 myLog.post("ERROR: Tasking error on chute WAIT.");
59 }
60 break;
61
62 default:
63 myLog.post("ERROR: Unknown request in chute.");
64 break;
65 }
66
67 } else {
68 idle = true;
69 try {
70 this.sleep(200);
71 } catch (InterruptedException e) {
72 // Like I give a rats-ass about this lame exception...
73 }
74 }
75
76 }
77
78 }
79
80 }
81
|